<?php
//check car info zsn 20170415 14:38
class CarModel extends RelationModel{
	
	protected $tableName = 'auto_total_locus'; //重新定义表名
	
	public function getList($queryType,$inputs){
		$p=$inputs["page"]?$inputs["page"]:1;
		$n=$inputs["rows"]?$inputs["rows"]:10;
		$limit = "limit ".($p-1)*$n.",".$n;
		$sort="";
        $where = "";
		if($inputs["sort"])
			$sort .= "order by ".$inputs["sort"]." ".$inputs["order"];
		//=============
		if(!empty($inputs['userid'])){
			$where .= " and userid = {$inputs['userid']} ";
		}
		if(!empty($inputs['plate_no'])){
			$where .= " and plate_no = '{$inputs['plate_no']}' ";
		}
		
		//======================
		$fields = "count(*) count";
		$sql = "select ".$fields." from `{$this->tableName}` atl  where 1=1 ".$where.";";
		//返回列表（limit分页）
		if($queryType=="list"){
			$where .= $sort." "." GROUP BY atl.userid ".$limit;
			$fields = " aob.id as obd_id,au.username,SUM(atl.avg_kmhour)/COUNT(atl.avg_kmhour) avg_kmhour,SUM(atl.total_mileage) total_mileage,SUM(atl.total_use_oil) total_use_oil,SUM(atl.avg_use_oil)/COUNT(atl.avg_use_oil) avg_use_oil,atl.userid,atl.plate_no,FROM_UNIXTIME(start_time,'%Y-%m-%d %H:%i:%s') start_time,start_addr,FROM_UNIXTIME(end_time,'%Y-%m-%d %H:%i:%s') end_time ";
			$sql = "select ".$fields." from `{$this->tableName}` atl
		       left JOIN auto_user au ON atl.userid = au.id
		       left JOIN auto_obd_bind aob ON atl.userid = aob.userid 
		       where 1=1 ".$where.";";
		}
		
		$model = new Model();
		return $model->query($sql);
	}

    public function getObd($userinfo){
       $sql ="SELECT snid FROM cars cs  
				LEFT JOIN cars_obd_bind cob ON cs.id = cob.cars_id
				LEFT JOIN product p ON p.id = cob.obd_id
				where cs.user_id =".$userinfo['id'];
         $model = new CarsModel();
         return $model->query($sql);
    }
	public function getplate_no($obd_no){
		$obd = implode("','",$obd_no);
	   	$sql = "SELECT aob.userid,au.username,aub.plate_no FROM auto_obd_bind aob 
			   left JOIN auto_user au ON au.id = aob.userid
			   left JOIN auto_user_bind aub ON   aub.userid = aob.userid
               WHERE aob.obd_no IN  "."( '".$obd."')";
	     $model = new CarsModel();
         return $model->query($sql);
	}
	  
	public function getCarmgListMotorcade($queryType,$userInfo,$inputs){
		$p=$inputs["page"]?$inputs["page"]:1;
		$n=$inputs["rows"]?$inputs["rows"]:10;
		$today = date("d",time());//当前日期
		$month_stime = date("Y-m-d 00:00:00",time() - 3600*24*($today-1));//当月开始的时间
		$fmonth_time = date("Ym",time() - 3600*24*($today-1));//当月时间

		$stime = $inputs["stime"]?date("Y-m-d 00:00:00",strtotime($inputs["stime"])):$month_stime;
		$etime = $inputs["etime"]?date("Y-m-d 23:59:59",strtotime($inputs["etime"])):"";
		$searchValue = urldecode(trim($inputs["searchValue"]));
		
		$limit = "limit ".($p-1)*$n.",".$n;
		$sort="";
		$where = "";
		if($inputs["sort"])
			$sort = "order by ".$inputs["sort"]." ".$inputs["order"];
		//=============
		if(!empty($inputs['userid']))
			$where .= " and userid = {$inputs['userid']} ";		
		if(!empty($searchValue))
			$where .=" and (au.username like '%".$searchValue."%' 
			 or au.mobile like '%".$searchValue."%' 
			 or aub.plate_no like '%".$searchValue."%') ";
		$where_atl = "";
		$where_fuc = "";		
		if(!empty($stime)){
			$where_atl .=" and atl.inputtime > '".$stime."' ";
//			$where_fuc .=" and fuc.updatetime > '".$stime."' ";
		}
		if(!empty($etime)){
			$where_atl .=" and atl.inputtime < '".$etime."' ";
//			$where_fuc .=" and fuc.updatetime < '".$etime."' ";
		}
//		if(empty($inputs["stime"]) && empty($inputs["etime"])){
//			$where_fuc .=" and fuc.cflag = '".$fmonth_time."' ";
//		}
		$where_fuc .=" and fuc.cflag = '".$fmonth_time."' ";
		//======================
		//返回列表（limit分页）
		if($queryType=="list"){
			$where .= " GROUP BY p.snid ".$sort." ".$limit;
			
			$sql = "select aob.userid,aob.obd_no,aub.plate_no,
					au.username,au.mobile,fuc.total,count(atl.id) count_journey,
					SUM(atl.total_mileage) total_mileage,
					SUM(atl.end_time-atl.start_time) total_way_time,
					SUM(atl.total_use_oil) total_use_oil from auto_obd_bind aob 
					join product p on aob.obd_no = p.snid
					join auto_user_bind aub on aub.userid = aob.userid
					join auto_user au on au.id = aob.userid
					left join flow_user_card fuc on fuc.userid = aob.userid  $where_fuc 
					left join auto_total_locus atl on aob.userid = atl.userid and atl.end_time > atl.start_time and atl.start_time > 0 and atl.end_time > 0 $where_atl
					where p.uid = {$userInfo['id']} and p.delete_type = 0 $where";
			
		}else if($queryType=="count"){
			$sql = "select count(1) count from product p 
		       JOIN auto_obd_bind aob ON p.snid = aob.obd_no
		       JOIN auto_user_bind aub ON aob.userid = aub.userid
		       where p.delete_type = 0 and p.uid = {$userInfo['id']};";
		}
		// echo $sql;
		$model = new Model();
		//echo $model->getLastSQL();
		return $model->query($sql);
	}
	
	//车辆监控
	public function getCarmoniListMonitor($queryType,$inputs){
		$p=$inputs["page"]?$inputs["page"]:1;
		$n=$inputs["rows"]?$inputs["rows"]:12;
		
		$motorcadeId = $inputs["motorcade"];
		$month = trim($inputs['month']);
		$condition = $inputs['condition'];//比较字段
		$compare = $inputs['compare'];//比较符号
		$compareData = trim($inputs['compareData']);//比较数据
		$searchValue = urldecode(trim($inputs["searchValue"]));

        $model = new Model();

		if($inputs['month'] == date("Ym",time())){
            $countDay = date("j");
		}else{
			$tmp_month = $inputs['month']."01";
			$countDay = date("t",strtotime($tmp_month));
		}

		$where = "";
        $order = "";
        $limit = "limit ".($p - 1)*$n.",".$n;
		if(!empty($compareData)){
			if($compare == "less")
				$symbol = "<";
			if($compare == "more")
				$symbol = ">";
			if($compare == "equals")
				$symbol = "=";
			//剩余流量的条件查询
            if($condition == "total"){
                $where .= " and cast(total/1024/1024 as decimal(8,2)) ".$symbol." ".$compareData;
            }elseif($condition == "dayFlow"){
                $where .= " and cast(total/1024/1024/".$countDay." as decimal(8,2)) ".$symbol." ".$compareData;
            }elseif($condition == "leftFlow"){
                $where .= " and (5600-(cast(total/1024/1024 as decimal(8,2)))) ".$symbol." ".$compareData;//应该是(5600-total)
            }elseif($condition == "timespan"){
                $where .= " and ROUND((timespan/3600),2) ".$symbol." ".$compareData;
            }elseif($condition == "dayTime"){
                $where .= " and ROUND((timespan/".$countDay."/3600),2) ".$symbol." ".$compareData;
            }elseif($condition == "dayMileage"){
                $where .= " and ROUND((mileage/".$countDay."),2) ".$symbol." ".$compareData;
            }elseif($condition == "dayPicnum"){
                $where .= " and ROUND((timespan/60/picnum),2) ".$symbol." ".$compareData;
            }elseif($condition == "dayVideonum"){
                $where .= " and ROUND((timespan/60/videonum),2) ".$symbol." ".$compareData;
            }elseif($condition == "noUpdatetime"){
                $where .= "";
            }else{
				$where .= " and ".$condition." ".$symbol." ".$compareData;
			}
		}
		if(!empty($searchValue) && $searchValue != "设备ID/车牌/用户名/手机号/SIM卡号"){
			$where .=" and (au.username like '%".$searchValue."%'
			 or au.mobile like '%".$searchValue."%' 
			 or aob.plate_no like '%".$searchValue."%' 
			 or p.snid like '%".$searchValue."%'
			 or fuc.card_no like '%".$searchValue."%') ";
		}else{
            $where .= ' and p.uid = "'.$motorcadeId.'"';
        }
        if($inputs['sort'] && $inputs['order']){
            $order .= " order by ".$inputs['sort']." ".$inputs['order'];
        }
		//返回列表（limit分页）
		if($queryType=="list"){
//            $pre_sql = "select totalflow from `auto_card_set` acs
//                        join `auto_card_user_map` acum on acs.id = acum.cardid
//                        where acum.userid = ".$motorcadeId.";";
//            $pre_result = $model->query($pre_sql);
//            $totalflow = $pre_result[0]['totalflow']?$pre_result[0]['totalflow']:5600;
            $AutoCardSetModel = M("AutoCardSet");
            $pre_result = $AutoCardSetModel->join('`auto_card_user_map` acum on auto_card_set.id = acum.cardid')->where('acum.userid = '.$motorcadeId)->getField('totalflow');
            $totalflow = $pre_result?$pre_result:5600;

			$fields = " p.uid,a_code,snid as obd_no,
			aob.plate_no,
			username,
			mobile,
			cast(total/1024/1024 as decimal(8,2)) as total
			,cast(total/1024/1024/".$countDay." as decimal(8,2)) as dayFlow,
			(".$totalflow."-(cast(total/1024/1024 as decimal(8,2)))) as leftFlow,
			ROUND((timespan/3600),2) as timespan,
			ROUND((timespan/".$countDay."/3600),2) as dayTime,
            mileage,
            ROUND((mileage/".$countDay."),2) as dayMileage,
            picnum,
            ROUND((timespan/60/picnum),2) as dayPicnum,
            videonum,
            ROUND((timespan/60/videonum),2) as dayVideonum,
            fuc.updatetime ";
            //'<span text-decoration=\"underline\" style=\"cursor:pointeer;\">定位</span>' as action
			$sql = "select ".$fields." 
				FROM  product p
				LEFT JOIN auto_obd_bind aob ON p.snid = aob.obd_no
				LEFT JOIN auto_user au ON aob.userid = au.id
				left join flow_user_card fuc on fuc.userid = aob.userid and fuc.cflag = '".$month."' 
				left join report_obd_total rot on aob.obd_no = rot.obdid and rot.cflag = '".$month."'
				LEFT JOIN rbac_user ru ON ru.id=p.uid
				LEFT JOIN `area` aa ON   aa.id=ru.area_id
				where 1=1 ".$where." ".$order." ".$limit.";";
		}else if($queryType=="count"){
//			$sql = "select count(1) count
//			from product p
//			left join auto_obd_bind aob on p.snid = aob.obd_no
//			where p.uid = ".$motorcadeId.";";
            $sql = "select count(1) as count
				FROM  product p
				LEFT JOIN auto_obd_bind aob ON p.snid = aob.obd_no
				LEFT JOIN auto_user au ON aob.userid = au.id
				left join flow_user_card fuc on fuc.userid = aob.userid and fuc.cflag = '".$month."'
				left join report_obd_total rot on aob.obd_no = rot.obdid and rot.cflag = '".$month."'
				LEFT JOIN rbac_user ru ON ru.id=p.uid
				LEFT JOIN `area` aa ON   aa.id=ru.area_id
				where 1=1 ".$where.";";
		}
//		var_dump($sql);
		return $model->query($sql);
	}

	//车辆监控--导出搜索结果
	public function getCarmoniOutListMonitor($queryType,$inputs){
		
		$motorcadeId = $inputs["motorcade"];
		$month = trim($inputs['month']);
		$condition = $inputs['condition'];//比较字段
		$compare = $inputs['compare'];//比较符号
		$compareData = trim($inputs['compareData']);//比较数据
		$searchValue = urldecode(trim($inputs["searchValue"]));

        $model = new Model();

		if($inputs['month'] == date("Ym",time())){
            $countDay = date("j");
		}else{
			$tmp_month = $inputs['month']."01";
			$countDay = date("t",strtotime($tmp_month));
		}
		$where = "";
        $order = "";
		if(!empty($compareData) && $compareData != 'compareData'){
			if($compare == "less")
				$symbol = "<";
			if($compare == "more")
				$symbol = ">";
			if($compare == "equals")
				$symbol = "=";
			//剩余流量的条件查询
            if($condition == "total"){
                $where .= " and cast(total/1024/1024 as decimal(8,2)) ".$symbol." ".$compareData;
            }elseif($condition == "dayFlow"){
                $where .= " and cast(total/1024/1024/".$countDay." as decimal(8,2)) ".$symbol." ".$compareData;
            }elseif($condition == "leftFlow"){
                $where .= " and (5600-(cast(total/1024/1024 as decimal(8,2)))) ".$symbol." ".$compareData;//应该是(5600-total)
            }elseif($condition == "timespan"){
                $where .= " and ROUND((timespan/3600),2) ".$symbol." ".$compareData;
            }elseif($condition == "dayTime"){
                $where .= " and ROUND((timespan/".$countDay."/3600),2) ".$symbol." ".$compareData;
            }elseif($condition == "dayMileage"){
                $where .= " and ROUND((mileage/".$countDay."),2) ".$symbol." ".$compareData;
            }elseif($condition == "dayPicnum"){
                $where .= " and ROUND((timespan/60/picnum),2) ".$symbol." ".$compareData;
            }elseif($condition == "dayVideonum"){
                $where .= " and ROUND((timespan/60/videonum),2) ".$symbol." ".$compareData;
            }elseif($condition == "noUpdatetime"){
                $where .= "";
            }else{
				$where .= " and ".$condition." ".$symbol." ".$compareData;
			}
		}
		if(!empty($searchValue) && $searchValue != "设备ID/车牌/用户名/手机号/SIM卡号"){
			$where .=" and (au.username like '%".$searchValue."%'
			 or au.mobile like '%".$searchValue."%' 
			 or aob.plate_no like '%".$searchValue."%' 
			 or p.snid like '%".$searchValue."%'
			 or fuc.card_no like '%".$searchValue."%') ";
		}else{
			if($motorcadeId != 'motorcade')
            	$where .= ' and p.uid = "'.$motorcadeId.'"';
        }
        if($inputs['sort'] && $inputs['order']){
            $order .= " order by ".$inputs['sort']." ".$inputs['order'];
        }
		//返回列表（limit分页）
        $AutoCardSetModel = M("AutoCardSet");
        $pre_result = $AutoCardSetModel->join('`auto_card_user_map` acum on auto_card_set.id = acum.cardid')->where('acum.userid = '.$motorcadeId)->getField('totalflow');
        $totalflow = $pre_result?$pre_result:5600;

		$fields = " p.uid,a_code,snid as obd_no,
		aob.plate_no,
		username,
		mobile,
		cast(total/1024/1024 as decimal(8,2)) as total
		,cast(total/1024/1024/".$countDay." as decimal(8,2)) as dayFlow,
		(".$totalflow."-(cast(total/1024/1024 as decimal(8,2)))) as leftFlow,
		ROUND((timespan/3600),2) as timespan,
		ROUND((timespan/".$countDay."/3600),2) as dayTime,
        mileage,
        ROUND((mileage/".$countDay."),2) as dayMileage,
        picnum,
        ROUND((timespan/60/picnum),2) as dayPicnum,
        videonum,
        ROUND((timespan/60/videonum),2) as dayVideonum,
        fuc.updatetime ";
        //'<span text-decoration=\"underline\" style=\"cursor:pointeer;\">定位</span>' as action
		$sql = "select ".$fields." 
			FROM  product p
			LEFT JOIN auto_obd_bind aob ON p.snid = aob.obd_no
			LEFT JOIN auto_user au ON aob.userid = au.id
			left join flow_user_card fuc on fuc.userid = aob.userid and fuc.cflag = '".$month."' 
			left join report_obd_total rot on aob.obd_no = rot.obdid and rot.cflag = '".$month."'
			LEFT JOIN rbac_user ru ON ru.id=p.uid
			LEFT JOIN `area` aa ON   aa.id=ru.area_id
			where 1=1 ".$where." ".$order." ;";
		// var_dump($sql);
		return $model->query($sql);
	}	

    public function getCarmgListTransport($queryType,$userInfo,$inputs){

        $model = new Model();
        $p=$inputs["page"]?$inputs["page"]:1;
        $n=$inputs["rows"]?$inputs["rows"]:10;
        $today = date("d",time());//当前日期
        $month_stime = date("Y-m-d 00:00:00",time() - 3600*24*($today-1));//当月开始的时间
        $fmonth_time = date("Ym",time() - 3600*24*($today-1));//当月时间

        $stime = $inputs["stime"]?date("Y-m-d 00:00:00",strtotime(trim($inputs["stime"]))):$month_stime;
        $etime = $inputs["etime"]?date("Y-m-d 23:59:59",strtotime(trim($inputs["etime"]))):"";
        $searchValue = urldecode(trim($inputs["searchValue"]));

        $limit = "limit ".($p-1)*$n.",".$n;
        $sort="";
        $where = "";
        if($inputs["sort"])
            $sort = "order by ".$inputs["sort"]." ".$inputs["order"];
        //=============
        if(!empty($inputs['userid']))
            $where .= " and userid = {$inputs['userid']} ";
        if(!empty($searchValue))
            $where .=" and (au.username like '%".$searchValue."%'
			 or au.mobile like '%".$searchValue."%'
			 or aub.plate_no like '%".$searchValue."%'
			 or tg.group_name like '%".$searchValue."%' ) ";
        $where_atl = "";
        $where_fuc = "";
        if(!empty($stime)){
            $where_atl .=" and atl.inputtime > '".$stime."' ";
        }
        if(!empty($etime)){
            $where_atl .=" and atl.inputtime < '".$etime."' ";
        }
        $where_fuc .=" and fuc.cflag = '".$fmonth_time."' ";



        //限制车辆显示，只可取出自己分组下的车辆
        $group_sql = "SELECT CAST(GROUP_CONCAT(tgr.group_id) AS CHAR) groupIdStr FROM rbac_user ru 
						JOIN rbac_role_user rru ON ru.id=rru.user_id 
						JOIN transport_group_role tgr ON tgr.role_id=rru.role_id 	
						WHERE ru.grade=3 AND account='". $userInfo['account']."'";
        $group_str = $model->query($group_sql);
        $group_str =  $group_str[0];
        // var_dump($group_str);
        if($group_str['groupIdStr'] != null)
        	$where .=" and tgm.group_id in (".$group_str['groupIdStr'].") ";



        //======================
        //返回列表（limit分页）
        if($queryType=="list"){
            $where .= " GROUP BY p.snid ".$sort." ".$limit;
            $fields = " aob.userid,aob.obd_no,aub.plate_no,aub.total_mileage mileage,au.username,tgm.remark,au.mobile,count(atl.id) count_journey,SUM(atl.total_mileage) total_mileage,SUM(atl.end_time-atl.start_time) total_way_time,SUM(atl.total_use_oil) total_use_oil,fuc.total,tg.group_name ";
        }else if($queryType=="count"){
           $fields = " count(distinct(aub.userid)) as count ";
        }
        $join_table = " auto_user_bind aub join auto_user au on aub.userid = au.id
				left join auto_total_locus atl on aub.userid = atl.userid and atl.end_time > atl.start_time and atl.start_time > 0 and atl.end_time > 0 ".$where_atl."
				join auto_obd_bind aob on aub.userid = aob.userid
				left join transport_group_map tgm on aob.obd_no = tgm.obd_no
				join product p on aob.obd_no = p.snid
				left join transport_group tg on tgm.group_id = tg.id 
				left join flow_user_card fuc on fuc.userid = au.id ".$where_fuc;
        if($userInfo['role_id']!=87){
        	$join_table .= " join transport_group_role tgr on tgm.group_id = tgr.group_id ";
        	$sql = "select ".$fields." from ".$join_table." where p.delete_type = 0 ".$where.";";
        }else{
        	$sql = "select ".$fields." from ".$join_table." where p.uid = {$userInfo['id']} and p.delete_type = 0 ".$where.";";
        }
        // echo $sql;
        return $model->query($sql);
    }

	public function getCarmgOutListTransport($queryType,$userInfo,$inputs){

        $model = new Model();
        // $p=$inputs["page"]?$inputs["page"]:1;
        // $n=$inputs["rows"]?$inputs["rows"]:10;
        $today = date("d",time());//当前日期
        $month_stime = date("Y-m-d 00:00:00",time() - 3600*24*($today-1));//当月开始的时间
        $fmonth_time = date("Ym",time() - 3600*24*($today-1));//当月时间

        $stime = $inputs["stime"]?date("Y-m-d 00:00:00",strtotime(trim($inputs["stime"]))):$month_stime;
        $etime = $inputs["etime"]?date("Y-m-d 23:59:59",strtotime(trim($inputs["etime"]))):"";
        $searchValue = urldecode(trim($inputs["searchValue"]));

        // $limit = "limit ".($p-1)*$n.",".$n;
        $sort="";
        $where = "";
        if($inputs["sort"])
            $sort = "order by ".$inputs["sort"]." ".$inputs["order"];
        //=============
        if(!empty($inputs['userid']))
            $where .= " and userid = {$inputs['userid']} ";
        if(!empty($searchValue) && $searchValue != '用户名')
            $where .=" and (au.username like '%".$searchValue."%'
			 or au.mobile like '%".$searchValue."%'
			 or aub.plate_no like '%".$searchValue."%'
			 or tg.group_name like '%".$searchValue."%' ) ";
        $where_atl = "";
        $where_fuc = "";
        if(!empty($stime)){
            $where_atl .=" and atl.inputtime > '".$stime."' ";
        }
        if(!empty($etime)){
            $where_atl .=" and atl.inputtime < '".$etime."' ";
        }
        $where_fuc .=" and fuc.cflag = '".$fmonth_time."' ";



        //限制车辆显示，只可取出自己分组下的车辆
        $group_sql = "SELECT CAST(GROUP_CONCAT(tgr.group_id) AS CHAR) groupIdStr FROM rbac_user ru 
						JOIN rbac_role_user rru ON ru.id=rru.user_id 
						JOIN transport_group_role tgr ON tgr.role_id=rru.role_id 	
						WHERE ru.grade=3 AND account='". $userInfo['account']."'";
        $group_str = $model->query($group_sql);
        $group_str =  $group_str[0];
        // var_dump($group_str);
        if($group_str['groupIdStr'] != null)
        	$where .=" and tgm.group_id in (".$group_str['groupIdStr'].") ";



        //======================
        //返回列表（limit分页）
        if($queryType=="list"){
            $where .= " GROUP BY p.snid ".$sort." ";
            $fields = " aub.plate_no,au.username,tg.group_name,au.mobile,aub.total_mileage mileage,count(atl.id) count_journey,SUM(atl.total_mileage) total_mileage,SUM(atl.end_time-atl.start_time) total_way_time,SUM(atl.total_use_oil) total_use_oil,aob.userid,fuc.total,tgm.remark";
        }else if($queryType=="count"){
           $fields = " count(distinct(aub.userid)) as count ";
        }
        $join_table = " auto_user_bind aub join auto_user au on aub.userid = au.id
				left join auto_total_locus atl on aub.userid = atl.userid and atl.end_time > atl.start_time and atl.start_time > 0 and atl.end_time > 0 ".$where_atl."
				join auto_obd_bind aob on aub.userid = aob.userid
				left join transport_group_map tgm on aob.obd_no = tgm.obd_no
				join product p on aob.obd_no = p.snid
				left join transport_group tg on tgm.group_id = tg.id 
				left join flow_user_card fuc on fuc.userid = au.id ".$where_fuc;
        if($userInfo['role_id']!=87){
        	$join_table .= " join transport_group_role tgr on tgm.group_id = tgr.group_id ";
        	$sql = "select ".$fields." from ".$join_table." where p.delete_type = 0 ".$where.";";
        }else{
        	$sql = "select ".$fields." from ".$join_table." where p.uid = {$userInfo['id']} and p.delete_type = 0 ".$where.";";
        }
        // echo $sql;
        return $model->query($sql);
    }    

	public function getPathListMonitor($motorcadeId,$inputs){
		$fields = " aob.plate_no,snid,nickname,p.cam_stat,p.update_time ";
		$join = " join rbac_user ru on ru.id = p.uid
				join auto_obd_bind aob on aob.obd_no = p.snid
		";
		$where = " ru.id = ".$motorcadeId." ";
		$sql = "select".$fields."from product p ".$join." where 1=1 and ".$where.";";
		$model = new Model();

		return $model->query($sql);
	}
}